package com.zhongkun.datahome.web.rest;

import com.zhongkun.datahome.common.annotation.Log;
import com.zhongkun.datahome.common.core.controller.BaseController;
import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.common.enums.BusinessType;
import com.zhongkun.datahome.service.req.IdsBody;
import com.zhongkun.datahome.service.req.cmd.house.CustomerHouseCmd;
import com.zhongkun.datahome.service.req.cmd.house.CustomerHouseServerCmd;
import com.zhongkun.datahome.service.req.qry.house.CustomerHouseQry;
import com.zhongkun.datahome.service.res.PageVo;
import com.zhongkun.datahome.service.res.house.CustomerHouseDetailVo;
import com.zhongkun.datahome.service.res.house.CustomerHouseVo;
import com.zhongkun.datahome.service.service.ICustomerHouseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 客户房产Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/core/house")
public class CustomerHouseController extends BaseController {
    @Resource
    private ICustomerHouseService customerHouseService;

    @ApiOperation("查询客户房产列表")
    @PreAuthorize("@ss.hasPermi('core:house:page')")
    @GetMapping("/page")
    public R<PageVo<CustomerHouseVo>> page(CustomerHouseQry qry) {
        return R.ok(customerHouseService.page(qry));
    }

    @ApiOperation("获取客户房产详细信息")
    @PreAuthorize("@ss.hasPermi('core:house:query')")
    @GetMapping(value = "/{id}")
    public R<CustomerHouseDetailVo> getInfo(@PathVariable("id") Long id) {
        return R.ok(customerHouseService.getInfo(id));
    }

    @ApiOperation("新增客户房产")
    @PreAuthorize("@ss.hasPermi('core:house:add')")
    @Log(title = "客户房产", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Long> add(@RequestBody CustomerHouseCmd cmd) {
        return R.ok(customerHouseService.add(cmd));
    }

    @ApiOperation("修改客户房产")
    @PreAuthorize("@ss.hasPermi('core:house:edit')")
    @Log(title = "客户房产", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody CustomerHouseCmd cmd) {
        customerHouseService.edit(cmd);
        return R.ok();
    }

    @ApiOperation("删除客户房产")
    @PreAuthorize("@ss.hasPermi('core:house:remove')")
    @Log(title = "客户房产", businessType = BusinessType.DELETE)
	@DeleteMapping
    public R<Void> remove(@RequestBody IdsBody idsBody) {
        customerHouseService.remove(idsBody.getIds());
        return R.ok();
    }

    @ApiOperation("添加房产服务人员")
    @PreAuthorize("@ss.hasPermi('core:house:addServer')")
    @Log(title = "房产服务团队", businessType = BusinessType.INSERT)
    @PostMapping("/addServer")
    public R<Void> addServer(@RequestBody CustomerHouseServerCmd cmd) {
        customerHouseService.addServer(cmd);
        return R.ok();
    }

    @ApiOperation("删除房产服务人员")
    @PreAuthorize("@ss.hasPermi('core:house:delServer')")
    @Log(title = "房产服务团队", businessType = BusinessType.DELETE)
    @DeleteMapping("/delServer")
    public R<Void> delServer(@RequestBody CustomerHouseServerCmd cmd) {
        customerHouseService.delServer(cmd);
        return R.ok();
    }

    @ApiOperation("删除房产服务人员")
    @Log(title = "房产服务团队", businessType = BusinessType.DELETE)
    @PostMapping("/fillAllCustomerHouseImg")
    public R<Void> fillAllCustomerHouseImg() {
        customerHouseService.fillAllCustomerHouseImg();
        return R.ok();
    }
}
